﻿using log4net.Core;
using log4net.Layout.Pattern;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using System.Web.UI.WebControls;

namespace X.LogHelper.CustomPatternConverter
{
    public class HttpUserIdPatternConverter : PatternLayoutConverter
    {
        protected override void Convert(TextWriter writer, LoggingEvent loggingEvent)
        {
            var result = string.Empty;
            result = "9527";
            //try
            //{
            //    var context = HttpContext.Current;
            //    if (null != context && null != context.Items && context.Items.Contains("UserId"))
            //    {
            //        var userid = context.Items["UserId"]?.ToString();
            //        if (!string.IsNullOrEmpty(userid))
            //            result = userid;
            //    }

            //}
            //catch { }
            writer.Write(result);
        }
    }

    public class HttpUserTypePatternConverter : PatternLayoutConverter
    {
        protected override void Convert(TextWriter writer, LoggingEvent loggingEvent)
        {
            var result = string.Empty;
            result = "1";
            //try
            //{
            //    var context = HttpContext.Current;
            //    if (null != context && null != context.Items && context.Items.Contains("UserType"))
            //    {
            //        var userid = context.Items["UserType"]?.ToString();
            //        if (!string.IsNullOrEmpty(userid))
            //            result = userid;
            //    }

            //}
            //catch { }
            writer.Write(result);
        }
    }

    public class HttpIPAddressPatternConverter : PatternLayoutConverter
    {
        protected override void Convert(TextWriter writer, LoggingEvent loggingEvent)
        {
            var result = string.Empty;
            result = "192.168.254.254";
            //try
            //{
            //    var context = HttpContext.Current;
            //    if (null != context && null != context.Items && context.Items.Contains("IPAddress"))
            //    {
            //        var userid = context.Items["IPAddress"]?.ToString();
            //        if (!string.IsNullOrEmpty(userid))
            //            result = userid;
            //    }

            //}
            //catch { }
            writer.Write(result);
        }
    }
     
    public class HttpTokenPatternConverter : PatternLayoutConverter
    {
        protected override void Convert(TextWriter writer, LoggingEvent loggingEvent)
        {
            var result = string.Empty;
            result = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
            //try
            //{
            //    var context = HttpContext.Current;
            //    if (null != context && null != context.Items && context.Items.Contains("Token"))
            //    {
            //        var userid = context.Items["Token"]?.ToString();
            //        if (!string.IsNullOrEmpty(userid))
            //            result = userid;
            //    }

            //}
            //catch { }
            writer.Write(result);
        }
    }
}
